1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gobject.TypeModule; 26 27 private import glib.Str; 28 private import gobject.ObjectG; 29 private import gobject.TypePluginIF; 30 private import gobject.TypePluginT; 31 private import gobject.c.functions; 32 public import gobject.c.types; 33 34 35 /** 36 * #GTypeModule provides a simple implementation of the #GTypePlugin 37 * interface. 38 * 39 * The model of #GTypeModule is a dynamically loaded module which 40 * implements some number of types and interface implementations. 41 * 42 * When the module is loaded, it registers its types and interfaces 43 * using g_type_module_register_type() and g_type_module_add_interface(). 44 * As long as any instances of these types and interface implementations 45 * are in use, the module is kept loaded. When the types and interfaces 46 * are gone, the module may be unloaded. If the types and interfaces 47 * become used again, the module will be reloaded. Note that the last 48 * reference cannot be released from within the module code, since that 49 * would lead to the caller's code being unloaded before g_object_unref() 50 * returns to it. 51 * 52 * Keeping track of whether the module should be loaded or not is done by 53 * using a use count - it starts at zero, and whenever it is greater than 54 * zero, the module is loaded. The use count is maintained internally by 55 * the type system, but also can be explicitly controlled by 56 * g_type_module_use() and g_type_module_unuse(). Typically, when loading 57 * a module for the first type, g_type_module_use() will be used to load 58 * it so that it can initialize its types. At some later point, when the 59 * module no longer needs to be loaded except for the type 60 * implementations it contains, g_type_module_unuse() is called. 61 * 62 * #GTypeModule does not actually provide any implementation of module 63 * loading and unloading. To create a particular module type you must 64 * derive from #GTypeModule and implement the load and unload functions 65 * in #GTypeModuleClass. 66 */ 67 public class TypeModule : ObjectG, TypePluginIF 68 { 69 /** the main Gtk struct */ 70 protected GTypeModule* gTypeModule; 71 72 /** Get the main Gtk struct */ 73 public GTypeModule* getTypeModuleStruct(bool transferOwnership = false) 74 { 75 if (transferOwnership) 76 ownedRef = false; 77 return gTypeModule; 78 } 79 80 /** the main Gtk struct as a void* */ 81 protected override void* getStruct() 82 { 83 return cast(void*)gTypeModule; 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GTypeModule* gTypeModule, bool ownedRef = false) 90 { 91 this.gTypeModule = gTypeModule; 92 super(cast(GObject*)gTypeModule, ownedRef); 93 } 94 95 // add the TypePlugin capabilities 96 mixin TypePluginT!(GTypeModule); 97 98 99 /** */ 100 public static GType getType() 101 { 102 return g_type_module_get_type(); 103 } 104 105 /** 106 * Registers an additional interface for a type, whose interface lives 107 * in the given type plugin. If the interface was already registered 108 * for the type in this plugin, nothing will be done. 109 * 110 * As long as any instances of the type exist, the type plugin will 111 * not be unloaded. 112 * 113 * Since 2.56 if @module is %NULL this will call g_type_add_interface_static() 114 * instead. This can be used when making a static build of the module. 115 * 116 * Params: 117 * instanceType = type to which to add the interface. 118 * interfaceType = interface type to add 119 * interfaceInfo = type information structure 120 */ 121 public void addInterface(GType instanceType, GType interfaceType, GInterfaceInfo* interfaceInfo) 122 { 123 g_type_module_add_interface(gTypeModule, instanceType, interfaceType, interfaceInfo); 124 } 125 126 /** 127 * Looks up or registers an enumeration that is implemented with a particular 128 * type plugin. If a type with name @type_name was previously registered, 129 * the #GType identifier for the type is returned, otherwise the type 130 * is newly registered, and the resulting #GType identifier returned. 131 * 132 * As long as any instances of the type exist, the type plugin will 133 * not be unloaded. 134 * 135 * Since 2.56 if @module is %NULL this will call g_type_register_static() 136 * instead. This can be used when making a static build of the module. 137 * 138 * Params: 139 * name = name for the type 140 * constStaticValues = an array of #GEnumValue structs for the 141 * possible enumeration values. The array is 142 * terminated by a struct with all members being 143 * 0. 144 * 145 * Returns: the new or existing type ID 146 * 147 * Since: 2.6 148 */ 149 public GType registerEnum(string name, GEnumValue* constStaticValues) 150 { 151 return g_type_module_register_enum(gTypeModule, Str.toStringz(name), constStaticValues); 152 } 153 154 /** 155 * Looks up or registers a flags type that is implemented with a particular 156 * type plugin. If a type with name @type_name was previously registered, 157 * the #GType identifier for the type is returned, otherwise the type 158 * is newly registered, and the resulting #GType identifier returned. 159 * 160 * As long as any instances of the type exist, the type plugin will 161 * not be unloaded. 162 * 163 * Since 2.56 if @module is %NULL this will call g_type_register_static() 164 * instead. This can be used when making a static build of the module. 165 * 166 * Params: 167 * name = name for the type 168 * constStaticValues = an array of #GFlagsValue structs for the 169 * possible flags values. The array is 170 * terminated by a struct with all members being 171 * 0. 172 * 173 * Returns: the new or existing type ID 174 * 175 * Since: 2.6 176 */ 177 public GType registerFlags(string name, GFlagsValue* constStaticValues) 178 { 179 return g_type_module_register_flags(gTypeModule, Str.toStringz(name), constStaticValues); 180 } 181 182 /** 183 * Looks up or registers a type that is implemented with a particular 184 * type plugin. If a type with name @type_name was previously registered, 185 * the #GType identifier for the type is returned, otherwise the type 186 * is newly registered, and the resulting #GType identifier returned. 187 * 188 * When reregistering a type (typically because a module is unloaded 189 * then reloaded, and reinitialized), @module and @parent_type must 190 * be the same as they were previously. 191 * 192 * As long as any instances of the type exist, the type plugin will 193 * not be unloaded. 194 * 195 * Since 2.56 if @module is %NULL this will call g_type_register_static() 196 * instead. This can be used when making a static build of the module. 197 * 198 * Params: 199 * parentType = the type for the parent class 200 * typeName = name for the type 201 * typeInfo = type information structure 202 * flags = flags field providing details about the type 203 * 204 * Returns: the new or existing type ID 205 */ 206 public GType registerType(GType parentType, string typeName, GTypeInfo* typeInfo, GTypeFlags flags) 207 { 208 return g_type_module_register_type(gTypeModule, parentType, Str.toStringz(typeName), typeInfo, flags); 209 } 210 211 /** 212 * Sets the name for a #GTypeModule 213 * 214 * Params: 215 * name = a human-readable name to use in error messages. 216 */ 217 public void setName(string name) 218 { 219 g_type_module_set_name(gTypeModule, Str.toStringz(name)); 220 } 221 222 /** 223 * Decreases the use count of a #GTypeModule by one. If the 224 * result is zero, the module will be unloaded. (However, the 225 * #GTypeModule will not be freed, and types associated with the 226 * #GTypeModule are not unregistered. Once a #GTypeModule is 227 * initialized, it must exist forever.) 228 */ 229 public void unuse() 230 { 231 g_type_module_unuse(gTypeModule); 232 } 233 234 /** 235 * Increases the use count of a #GTypeModule by one. If the 236 * use count was zero before, the plugin will be loaded. 237 * If loading the plugin fails, the use count is reset to 238 * its prior value. 239 * 240 * Returns: %FALSE if the plugin needed to be loaded and 241 * loading the plugin failed. 242 */ 243 public bool use() 244 { 245 return g_type_module_use(gTypeModule) != 0; 246 } 247 }